<template>
  <el-form ref="form"  :rules="formRules" :model="news" label-width="80px" label-position="left">
    <el-form-item label="新闻标题" prop="title">
      <el-input type="text" v-model="news.title" ></el-input>
    </el-form-item>
    <el-form-item label="新闻内容" prop="content">
      <el-input type="text" v-model="news.content"></el-input>
    </el-form-item>
    <el-form-item label="作者" prop="author">
      <el-input  v-model="news.author"></el-input>
    </el-form-item>
    <el-form-item label="发表时间">
      <el-date-picker v-model="news.createDate" type="datetime" value-format="yyyy-MM-dd"></el-date-picker>
    </el-form-item>
    <el-form-item>
      <el-button type="warning" @click="updateNews()">修改</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
    export default {
      name: "UpdateNews",
      data(){
        return{
          news:{

          },
          formRules:{
            title:[{required:true,message:"标题不能为空",trigger:"blur"}],
            content:[{required:true,message:"内容不能为空",trigger:"blur"}],
            author:[{required:true,message:"密码不能为空",trigger:"blur"}]
          }
        }
      },
      methods:{
        updateNews(){
          this.$refs['form'].validate((valid)=>{
            if(valid){
              this.axios({
                method:"put",
                url:"news",
                data:this.news
              }).then((res)=>{
                alert("修改成功")
                this.$router.push("/showNews")
              })
            }else{
              alert("修改失败")
              return;
            }
          })

        }
      },
      created() {
        this.news=this.$route.query.news
        console.log(this.news)
      }
    }
</script>

<style scoped>

</style>
